from selenium import webdriver
from time import sleep
#1.创建Chrome浏览器对象，这会在电脑上在打开一个浏览器窗口
browser = webdriver.Chrome(executable_path ="D:\chromedriver.exe")
#2.通过浏览器向服务器发送URL请求
browser.get("https://v.youku.com/v_show/id_XNTEwMTg0NjE5Mg==.html?spm=a2h0c.8166622.PhoneSokuProgram_1.dselectbutton_1&showid=ceba4745ea10415eb791")

print("start")
sleep(1)
#滚动到底部
js = "window.scrollTo(0,document.body.scrollHeight)"
browser.execute_script(js)

#
# 获取结果数目
user = browser.find_elements_by_xpath("//div[@class='comment-list-all']/div[@class='comment-list-item']")
for i in user:
    print(i.find_element_by_xpath(".//div[@class='comment-list-content-text']").text)
print(len(user))
print("------------------------------")


# sleep(1)
# #滚动到底部
# js = "window.scrollTo(0,document.body.scrollHeight)"
# browser.execute_script(js)
# #点击：查看更多评论
# elem1=browser.find_element_by_link_text("查看更多评论")
# elem1.click()
# sleep(1)
# # 获取结果数目
# user = browser.find_elements_by_xpath("//div[@class='comment-list-all']/div[@class='comment-list-item']")
# for i in user:
#     print(i.find_element_by_xpath(".//div[@class='comment-list-content-text']").text)
# print(len(user))
# print("------------------------------")


